from common.http_request import HttpRequest
import time

from common.server import CommonServer


class Server(HttpRequest):
    def __init__(self):
        super().__init__()
        self.common = CommonServer()

    def get_gjclxs_datas(self, times='LAST10'):
        res = self.request(
            url="https://data.stats.gov.cn/easyquery.htm",
            method="GET",
            params={
                "m": "QueryData",
                "dbcode": "hgnd",
                "rowcode": "zb",
                "colcode": "sj",
                "wds": "[]",
                "dfwds": '[{"wdcode":"zb","valuecode":"A0E010Y"}, {"wdcode":"sj", "valuecode":"' + times + '"}]',
                "k1": str(int(round(time.time() * 1000))),
                "h": 1
            }
        )
        return self.json(res)

    def get_hylrfz_datas(self, times='LAST10'):
        res = self.request(
            url="https://data.stats.gov.cn/easyquery.htm",
            method="GET",
            params={
                "m": "QueryData",
                "dbcode": "hgnd",
                "rowcode": "zb",
                "colcode": "sj",
                "wds": "[]",
                "dfwds": '[{"wdcode":"zb","valuecode":"A0N0Q06"}, {"wdcode":"sj", "valuecode":"' + times + '"}]',
                "k1": str(int(round(time.time() * 1000))),
                "h": 1
            }
        )
        return self.json(res)

    def get_sdzjbz_datas(self, times='LAST10'):
        res = self.request(
            url="https://data.stats.gov.cn/easyquery.htm",
            method="GET",
            params={
                "m": "QueryData",
                "dbcode": "hgnd",
                "rowcode": "zb",
                "colcode": "sj",
                "wds": "[]",
                "dfwds": '[{"wdcode":"zb","valuecode":"A0203"}, {"wdcode":"sj", "valuecode":"' + times + '"}]',
                "k1": str(int(round(time.time() * 1000))),
                "h": 1
            }
        )
        return self.json(res)
